import { Injectable } from "@angular/core";
import { HttpClient, HttpParams } from "@angular/common/http";
import { BaseHttpService } from "../../../app/shared/services/baseHttp.service";
import { Observable } from "rxjs";

@Injectable()
export class WeightMatricesService extends BaseHttpService {
    constructor(private http: HttpClient) {
        super();
    }

    public getSlots(): Observable<number> {
        return this.http.get<number>(this.serverUrl + 'esgratingserv/api/v1/esgratings/weightmatrices/slots');
    }

    public getAccounts(): Observable<any[]> {
        let params = new HttpParams();
        params = params.set('name', '')
            .set('orderAscending', true.toString())
            .set('orderBy', 'name')
            .set('skip', '0')
            .set('take', '5000')
            .set('status', 'Active')
            .set('tier1_or_tier2', false.toString());
        return this.http.get<any[]>(this.serverUrl + 'accountsserv/api/v1/accounts/', { params: params })

    }

    public getMatrices(accountId: string): Observable<any[]> {
        let params = new HttpParams();
        params = params.set('accountId', accountId);
        return this.http.get<any[]>(this.serverUrl + 'esgratingserv/api/v1/esgratings/weightmatrices', { params: params })
    }

    public getScheduledMatrices(accountId: string): Observable<any[]> {
        return this.http.patch<any[]>(this.serverUrl + 'esgratingserv/api/v1/esgratings/weightmatrices/scheduledWM/' + accountId, {});
    }

    public removeMatrix(matrixId: string): Observable<void> {
        return this.http.delete<void>(this.serverUrl + '/esgratingserv/api/v1/esgratings/weightmatrices/' + matrixId);
    }
}